var app = getApp();
Page({
    data:{
        page : {
            isend : false,
            doing : false,
            doo : 'ctyagent',
            pdata : {
                op : 'orderlist',
                page : 1,
                status : 0,
                time : '',
                shopid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        tab : {
            color : '#fb2d37',
            list: [{
            id: '0',
                title: '全部',
            },{
            id: '1',
                title: '已支付',
            }, {
            id: '2',
                title: '已完成',
            }, {
            id: '3',
                title: '已退款',
            }],
            selectedId: '0',
            scroll: false
        },
        datalist : [],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        self.setData({
            options : options,
            'page.pdata.status' : options.status ? options.status : 0,
            'page.pdata.time' : options.time ? options.time : '',
            'page.pdata.shopid' : options.shopid ? options.shopid : '',
        });
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,20,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   params : res.data.data.params,
                },function(){
                    self.setData({
                        inited : true,
                    });
                });

            },false,function(res){
                app.com.alert(res.data.message,function(){
                    if( res.data.errno == 3 ){
                        self.setData({
                            needback : true,
                        }) 
                        wx.navigateTo({
                            url : '/zofui_sales/ctyagent/join'
                        });
                    }
                });
            });
        });

        wx.setNavigationBarTitle({
            title:  '订单记录',
        });
        
    },
    tab(e){
        var self = this;
        var index = e.detail.index;
        if( self.data.ising || index == self.data.page.pdata.status ) return false;
        self.data.ising = true;
        
        self.setData({
            datalist : [],
            'page.pdata.status' : index,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
        self.data.ising = false;
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
            'page.pdata.page' : 1,
            'page.isend' : false,
        });
        
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})